package com.openess.bigsearch.engine.utils.sort;

import java.util.Comparator;

/**
 * 直接选择排序
 * 
 * @author TuTu
 * 
 */
public class SelectSort<E> implements Sort<E> {
	public void sort(E[] array, int p, int r, Comparator<? super E> c) {
		for (int i = p; i < r; i++) {
			int min = i;
			for (int j = i + 1; j <= r; j++)
				if (c.compare(array[j], array[min]) < 0)
					min = j;
			if (min != i) {
				E temp = array[min];
				array[min] = array[i];
				array[i] = temp;
			}
		}
	}
}
